<template>
    <div>

        <table border="1" width="1000" height="200" align="center" cellspacing="0" cellpadding="6">

            <tr align="center">
                <td>用户名</td>
                <td>用户密码</td>
                <td>添加用户</td>
                <td>修改信息</td>
                <td>详细信息</td>
                <td>删除</td>
            </tr>


            <!-- v-for="(user, index) in userlist" :key="index"  -->
            <tr align="center">
                <td>{{userlist.username}}</td>
                <td>******</td>
                <td><a-button type="link" @click="add">添加</a-button></td>
                <td><a-button type="link" @click="alter(userlist.id)">去修改</a-button></td>
                <td><a-button type="link" @click="gett(userlist.id)">查看</a-button></td>
                <td><a-button type="link" @click="del(userlist.id)">Delete</a-button></td>
            </tr>

        </table>

    </div>
</template>

<script>



export default {
    data() {
        return {
            userlist:[],
            uid:localStorage.getItem('uid'),
            number:"1"
        }
    },


    mounted:function(){

        this.axios.get('http://localhost:8000/users/',{params:{'uid':this.uid}}).then(res=>{
            
            if (res.data.code == 400){
              this.$toast('您没有该页面的访问权限')
              this.$router.push({path:'/ant_details'})
            }else{
                console.log(res.data)
                this.userlist = res.data
            }
            
        });

        this.zi_data()

    },

    methods:{
        add(){
            this.$router.push({path:'/myreg'})
        },

        alter(id){
            this.$router.push({query:{id:id},path:'/alter'})
        },

        del(id){
            this.axios.post("http://localhost:8000/delete/",this.qs.stringify({'id':id})).then(res=>{
                console.log(res.data)
                location.reload()
            })
        },

        gett(id){
            this.$router.push({path:'/ant_details',query:{'id':id,'number':'2'}})
        },

        zi_data(){
            this.$emit('pro_fu', this.number)  // 将子组件的内容赋值给pro_fu，传递到父组件
        }

    }

}
</script>

<style>

</style>